package dell.yangzhou;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class DemoLambda02 {
    public static void main(String[] args) {
        //匿名内部类的写法
        happyTime(600,new Consumer<Double>() {
            @Override
            public void accept(Double aDouble) {
                System.out.println("矿泉水"+aDouble);
            }
        });
        List<String>list= Arrays.asList("北京","天津","东京","南京");
        List<String> list1 = filterString(list, new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.contains("京");
            }
        });
        System.out.println(list1);
        List<String>list2=filterString(list,s->s.contains("京"));
        System.out.println(list2);
        System.out.println("=================");
        //lambda表达式的写法
       happyTime(200,money-> System.out.println("水,价格为"+money));
      //  filterString(Arrays.asList("小说","不说","该说","不该说"),pre->)
    }
    public static void happyTime(double money, Consumer con){
        con.accept(money);
    }
    //根据给定的规则，过滤集合中的字符串，此规则由Predicate中的test（）方法决定
    public static List<String> filterString(List<String>list, Predicate<String>pre){
        ArrayList<String>filterList=new ArrayList<>();
        for (String s:filterList){
           if (pre.test(s)){
               //test（）就是一个过滤方法
               filterList.add(s);
           }
        }
        return filterList;
    }
}
